import numpy as np
import pandas as pd
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
import plotly.graph_objs as go
import matplotlib.pyplot as plt
import cufflinks as cf
%matplotlib inline
import plotly.express as px
import folium
init_notebook_mode(connected=True)
cf.go_offline()
df = pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\Covid cases in India.xlsx')
df
df.drop('S. No.',axis=1,inplace=True)
#craetw a new column named as total cases
df['total_cases'] = df['Total Confirmed cases (Indian National)']+df['Total Confirmed cases ( Foreign National )']
#to show the most cases we are using abck gradient
df.style.background_gradient(cmap='Reds')
cases_in_each_state=df.groupby('Name of State / UT')['total_cases'].sum().sort_values(ascending=False).to_frame().reset_index()
#States of India and Total cases in each state
cases_in_each_state.style.background_gradient(cmap='PuBu')
#States of India vs Total cases
df.iplot(kind='bar',x='Name of State / UT',y='total_cases',color='red',title='States of India vs Total cases',xTitle='States of India',yTitle='Total cases')
df.iplot(kind='scatter',x='Name of State / UT',y='total_cases',color='red',mode='markers+lines',title='States of India vs Total cases',xTitle='States of India',yTitle='Total cases')
#correlation between each and every column
t = df.corr()
t
import seaborn as sns # another data visuvalization tool
plt.figure(figsize=(10,8)) #using matplotlib library
sns.heatmap(df.corr(),annot=True)
#coordinates of each state in india
#dataset contains all states latitude and longitude
india_coordinates = pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\Indian Coordinates.xlsx')
india_coordinates
#Here we are merging the dataframes of orginal dataframe and coordinates dataframe
df_new = pd.merge(india_coordinates,df,on='Name of State / UT')
df_new
#for geo locations
import folium
locations_of_india = df_new[['Latitude','Longitude']]
locationlist_of_india = locations_of_india.values.tolist()
len(locationlist_of_india)
map = folium.Map(location=[20, 70], zoom_start=5)
for points in range(0, len(locationlist_of_india)):
folium.Marker(locationlist_of_india[points], popup=df_new['Name of State / UT'][points]).add_to(map)
map
#how the COVID-19 raising globally by data viz(taken only four countries)
india_cases=pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\per_day_cases.xlsx',parse_dates=True,sheet_name='India')
italy_cases=pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\per_day_cases.xlsx',parse_dates=True,sheet_name='Italy')
SKorea_cases=pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\per_day_cases.xlsx',parse_dates=True,sheet_name='Korea')
china_cases=pd.read_excel(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\per_day_cases.xlsx',parse_dates=True,sheet_name='Wuhan')
india_cases
#data viz
fig = px.bar(data_frame=india_cases,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in india')
fig.show()
india_cases.iplot(kind='scatter',x='Date',y='Total Cases',mode='markers+lines',color='#FF6847')
fig = px.bar(data_frame=italy_cases,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in italy')
fig.show()
italy_cases.iplot(kind='scatter',x='Date',y='Total Cases',mode='markers+lines',color='#FF6847')
fig = px.bar(data_frame=SKorea_cases,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in southkorea')
fig.show()
SKorea_cases.iplot(kind='scatter',x='Date',y='Total Cases',mode='markers+lines',color='#FF6847')
fig = px.bar(data_frame=china_cases,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in wuhan')
fig.show()
china_cases.iplot(kind='scatter',x='Date',y='Total Cases',mode='markers+lines',color='#FF6847')
#Box plot of the original dataframe to know from where to where the cases vary
df.iplot(kind='box')
# COVI19 world data collected(from that data)
df=pd.read_csv(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\covid_19_data.csv',parse_dates=['Last Update'])
df
df.rename(columns={'Country/Region':'Country','Province/State':'State'},inplace=True)
df.query('Country=="India"')
df.groupby('ObservationDate').sum()
confirmed = df.groupby('ObservationDate').sum()['Confirmed'].reset_index()
deaths = df.groupby('ObservationDate').sum()['Deaths'].reset_index()
recoverd = df.groupby('ObservationDate').sum()['Recovered'].reset_index()
deaths
#data viz
fig = go.Figure()
fig.add_trace(go.Scatter(x=confirmed['ObservationDate'],y=confirmed['Confirmed'],mode='lines+markers',name='Confirmed',line=dict(color='green',width=2)))
fig.add_trace(go.Scatter(x=deaths['ObservationDate'],y=deaths['Deaths'],mode='lines+markers',name='Deaths',line=dict(color='red',width=2)))
fig.add_trace(go.Scatter(x=recoverd['ObservationDate'],y=recoverd['Recovered'],mode='lines+markers',name='Recovered',line=dict(color='blue',width=2)))
df_confirmed=pd.read_csv(r'C:\Users\HP\Desktop\COVID-19-Time-Series-Forecasting-with-Data-Analysis-master\time_series_covid_19_confirmed.csv')
df_confirmed
df_confirmed.rename(columns={'Country/Region':'Country'},inplace=True)
df_latlong_world=pd.merge(df,df_confirmed,on=['Country'])
df_latlong_world
fig=px.density_mapbox(df_latlong_world,lat='Lat',lon='Long',hover_name='Province/State',hover_data=['Confirmed','Deaths','Recovered'],animation_frame='ObservationDate',color_continuous_scale='portland',zoom=0,radius=7,height=700)
fig.update_layout(title='World wide corana virus')
fig.update_layout(mapbox_style='open-street-map',mapbox_center_lon=0)
fig.update_layout(margin={'r':0,'t':0,'l':0,'b':0})